package com.gw.jpa.controller;

import com.gw.jpa.entity.Grade;
import com.gw.jpa.repository.GradeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class GraderController {
    @Autowired
    private GradeRepository gradeRepository;
    @PostMapping("/grade")//添加班级信息
    public Grade addGrade(Grade grade){
        Grade grade1=null;
        grade1=gradeRepository.save(grade);
        return grade1;
    }
    @GetMapping("/grade/{gid}")//通过班级id获得班级信息
    public Grade getGrade(@PathVariable("gid") Integer gid){
        Grade grade=null;
        grade=gradeRepository.findById(gid).get();
        return grade;
    }
    @PutMapping("/grade")//更新班级信息
    public Grade modifyGrade(Grade grade){
        Grade grade1=null;
        grade1=gradeRepository.save(grade);
        return grade1;
    }
    @DeleteMapping("/grade/{gid}")//通过班级id删除指定的班级信息
    public void deleteGrade(@PathVariable("gid") Integer gid){
        gradeRepository.deleteById(gid);
    }
    @GetMapping("/grade")//获得全部班级信息
    public List<Grade> getGradeJquery(){
        List<Grade> list=null;
        list=gradeRepository.findAll();
        return list;
    }
}
